// pages/complaint/complaint.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputlength: 0,
    pingzhenglist: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#000',
    })
  },

  wheninput: function (e) {
    // console.log(e.detail.value.length)
    this.setData({
      inputlength: e.detail.value.length
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */

  uploadMedical: function () {
    var uqid = this.data.uqid;
    console.log(uqid)
    var that = this
    wx.showActionSheet({
      itemList: ['从相册选取', '拍照'],
      success(res) {
        console.log(res.tapIndex)
        var index = res.tapIndex;

        var pingzhenglist = that.data.pingzhenglist;
        if (index == 0) {

          let num = 3; //一次最大上传九张

          if (pingzhenglist.length > 0) {
            num = 3 - pingzhenglist.length;
          }

          wx.chooseImage({
            count: num,
            sizeType: ['original', 'compressed'],
            sourceType: ['album'],
            success(res) {
              console.log(res)
              // tempFilePath可以作为img标签的src属性显示图片
              const tempFilePaths = res.tempFilePaths;
              console.log(tempFilePaths)

              for (let i = 0; i < tempFilePaths.length; i++) {
                pingzhenglist.push(tempFilePaths[i])
              }
              that.setData({
                pingzhenglist: pingzhenglist
              });
            }
          })
        } else if (index == 1) {
          wx.chooseImage({
            count: 1,
            sizeType: ['original', 'compressed'],
            sourceType: ['camera'],
            success(res) {
              console.log(res)
              // tempFilePath可以作为img标签的src属性显示图片

              var pingzhenglist = that.data.pingzhenglist;

              const tempFilePaths = res.tempFilePaths;

              pingzhenglist.push(tempFilePaths[0])
              that.setData({
                pingzhenglist: pingzhenglist
              });
            }
          })
        }

      },
      fail(res) {
        console.log(res.errMsg)
      }
    })

  },

  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})